home *** CD-ROM | disk | FTP | other *** search
- Path: news.mistral.co.uk!usenet
- From: mikebarnard@mistral.co.uk (Mike Barnard)
- Newsgroups: comp.lang.c
- Subject: Re: Initialising structure members - help please!
- Date: Tue, 20 Feb 1996 11:54:07 GMT
- Organization: Mistral Internet (Brighton)
- Message-ID: <4gckb1$77e@news.mistral.co.uk>
- References: <4gb8hn$3m8@news.mistral.co.uk> <31298EF1.5F2C@cmt.lpr.mail.carel.fi>
- NNTP-Posting-Host: l56.mistral.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi Aril and Peter.
-
- Thanks for your replies.
-
- You said...
-
- >>one.number = 1;
- >>one.description = "1. Calculate a minefield";
-
- >You can't copy C strings with an "=". You must use the strcpy() function.
-
- and...
-
- >Since you declared 'description' as an array of chars, use strcpy(one.description,
- >"whatever string"); Be sure you won't use longer strings than the space available. A
- >better approach would be to declare 'decription' as a 'char *' and then malloc
- >enough space for whatever string you're going to place into it. (Also, your syntax
- >would work in that case.) The last two will work if you add & in front of them.
-
- Thanks, I'll look at what this means. But as a learning question, (not
- an argumentative one!!!), why does this good old boy work then?
-
- char name[]="An array of characters";
-
- Surely "name" is an array of characters as is my "description"? It
- works here. Doesn't it? This leads me on to another question actually,
- but I'll start another thread with it I think.
-
- Thanks again.
-
- ---
- Mic.
- From very windy and now snowy Worthing; England.
- mikebarnard@mistral.co.uk
-
- (I just lost 4 fence panels to the wind here! The cost of
- replacing them could have bought me a new windows compiler!)
-
-